from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-02-22 14:02:21.303778
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Tue, 22, Feb, 2022
Time: 14:02:26
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -48.2268
Nobs: 575.000 HQIC: -48.6425
Log likelihood: 6808.14 FPE: 5.74631e-22
AIC: -48.9083 Det(Omega_mle): 4.92036e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.347581 0.068321 5.087 0.000
L1.Burgenland 0.106260 0.041529 2.559 0.011
L1.Kärnten -0.110820 0.021629 -5.124 0.000
L1.Niederösterreich 0.188279 0.086596 2.174 0.030
L1.Oberösterreich 0.132066 0.085647 1.542 0.123
L1.Salzburg 0.254847 0.043965 5.797 0.000
L1.Steiermark 0.037260 0.058039 0.642 0.521
L1.Tirol 0.100165 0.046820 2.139 0.032
L1.Vorarlberg -0.069478 0.041277 -1.683 0.092
L1.Wien 0.020743 0.076126 0.272 0.785
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.052795 0.147409 0.358 0.720
L1.Burgenland -0.038197 0.089602 -0.426 0.670
L1.Kärnten 0.041475 0.046666 0.889 0.374
L1.Niederösterreich -0.204821 0.186838 -1.096 0.273
L1.Oberösterreich 0.461513 0.184791 2.497 0.013
L1.Salzburg 0.282138 0.094858 2.974 0.003
L1.Steiermark 0.113159 0.125224 0.904 0.366
L1.Tirol 0.304521 0.101019 3.014 0.003
L1.Vorarlberg 0.025597 0.089058 0.287 0.774
L1.Wien -0.028773 0.164248 -0.175 0.861
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.199587 0.034895 5.720 0.000
L1.Burgenland 0.088586 0.021211 4.176 0.000
L1.Kärnten -0.007393 0.011047 -0.669 0.503
L1.Niederösterreich 0.239332 0.044229 5.411 0.000
L1.Oberösterreich 0.162148 0.043744 3.707 0.000
L1.Salzburg 0.039747 0.022455 1.770 0.077
L1.Steiermark 0.026624 0.029643 0.898 0.369
L1.Tirol 0.081890 0.023913 3.424 0.001
L1.Vorarlberg 0.053632 0.021082 2.544 0.011
L1.Wien 0.117897 0.038881 3.032 0.002
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.120382 0.034852 3.454 0.001
L1.Burgenland 0.043135 0.021185 2.036 0.042
L1.Kärnten -0.013022 0.011033 -1.180 0.238
L1.Niederösterreich 0.168589 0.044174 3.816 0.000
L1.Oberösterreich 0.337657 0.043690 7.728 0.000
L1.Salzburg 0.100625 0.022427 4.487 0.000
L1.Steiermark 0.110747 0.029607 3.741 0.000
L1.Tirol 0.090202 0.023884 3.777 0.000
L1.Vorarlberg 0.060978 0.021056 2.896 0.004
L1.Wien -0.019603 0.038833 -0.505 0.614
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.122443 0.065633 1.866 0.062
L1.Burgenland -0.046594 0.039895 -1.168 0.243
L1.Kärnten -0.045292 0.020778 -2.180 0.029
L1.Niederösterreich 0.135711 0.083189 1.631 0.103
L1.Oberösterreich 0.165860 0.082277 2.016 0.044
L1.Salzburg 0.284027 0.042235 6.725 0.000
L1.Steiermark 0.057124 0.055755 1.025 0.306
L1.Tirol 0.156214 0.044978 3.473 0.001
L1.Vorarlberg 0.097160 0.039653 2.450 0.014
L1.Wien 0.076249 0.073130 1.043 0.297
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.080912 0.051160 1.582 0.114
L1.Burgenland 0.025711 0.031098 0.827 0.408
L1.Kärnten 0.053549 0.016196 3.306 0.001
L1.Niederösterreich 0.189210 0.064845 2.918 0.004
L1.Oberösterreich 0.329522 0.064135 5.138 0.000
L1.Salzburg 0.035176 0.032922 1.068 0.285
L1.Steiermark 0.005119 0.043461 0.118 0.906
L1.Tirol 0.120239 0.035060 3.430 0.001
L1.Vorarlberg 0.066592 0.030909 2.154 0.031
L1.Wien 0.095776 0.057005 1.680 0.093
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.170772 0.061828 2.762 0.006
L1.Burgenland 0.004431 0.037582 0.118 0.906
L1.Kärnten -0.065949 0.019573 -3.369 0.001
L1.Niederösterreich -0.107808 0.078366 -1.376 0.169
L1.Oberösterreich 0.208411 0.077508 2.689 0.007
L1.Salzburg 0.053886 0.039787 1.354 0.176
L1.Steiermark 0.249141 0.052523 4.743 0.000
L1.Tirol 0.499777 0.042371 11.795 0.000
L1.Vorarlberg 0.064439 0.037354 1.725 0.085
L1.Wien -0.073851 0.068891 -1.072 0.284
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.160076 0.068600 2.333 0.020
L1.Burgenland -0.003355 0.041699 -0.080 0.936
L1.Kärnten 0.062810 0.021717 2.892 0.004
L1.Niederösterreich 0.164819 0.086950 1.896 0.058
L1.Oberösterreich -0.053728 0.085997 -0.625 0.532
L1.Salzburg 0.207460 0.044145 4.700 0.000
L1.Steiermark 0.140263 0.058276 2.407 0.016
L1.Tirol 0.055742 0.047012 1.186 0.236
L1.Vorarlberg 0.146869 0.041445 3.544 0.000
L1.Wien 0.122074 0.076437 1.597 0.110
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.393009 0.040253 9.764 0.000
L1.Burgenland -0.003611 0.024467 -0.148 0.883
L1.Kärnten -0.021324 0.012743 -1.673 0.094
L1.Niederösterreich 0.200112 0.051019 3.922 0.000
L1.Oberösterreich 0.229482 0.050460 4.548 0.000
L1.Salzburg 0.037254 0.025903 1.438 0.150
L1.Steiermark -0.015930 0.034195 -0.466 0.641
L1.Tirol 0.090699 0.027585 3.288 0.001
L1.Vorarlberg 0.050899 0.024319 2.093 0.036
L1.Wien 0.042364 0.044851 0.945 0.345
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.036255 0.101859 0.169256 0.136392 0.095322 0.081462 0.032116 0.210027
Kärnten 0.036255 1.000000 -0.027745 0.132387 0.048262 0.085259 0.443969 -0.067289 0.089133
Niederösterreich 0.101859 -0.027745 1.000000 0.310037 0.118961 0.270010 0.065589 0.151414 0.287714
Oberösterreich 0.169256 0.132387 0.310037 1.000000 0.214390 0.293213 0.167204 0.136356 0.234972
Salzburg 0.136392 0.048262 0.118961 0.214390 1.000000 0.123878 0.091215 0.104242 0.123888
Steiermark 0.095322 0.085259 0.270010 0.293213 0.123878 1.000000 0.134093 0.105832 0.032662
Tirol 0.081462 0.443969 0.065589 0.167204 0.091215 0.134093 1.000000 0.062030 0.151183
Vorarlberg 0.032116 -0.067289 0.151414 0.136356 0.104242 0.105832 0.062030 1.000000 -0.004853
Wien 0.210027 0.089133 0.287714 0.234972 0.123888 0.032662 0.151183 -0.004853 1.000000